//
//  RecommendCell.m
//  BaseFramework01
//
//  Created by IMAC on 2017/6/2.
//  Copyright © 2017年 IMAC. All rights reserved.
//

#import "RecommendCell.h"

#define  EDAGEINSET 10.0
@implementation RecommendCell
{
    UIView *_contentBGView;
     UILabel *_titleLabel;
     UILabel *_typeLabel;
     UILabel *_timeLabel;
     UILabel *_visitLabel;
    UIImageView *_imageView;
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.clipsToBounds  =YES;
        
        UIView *contentBGView = [[UIView alloc]init];
//        contentBGView.backgroundColor = [UIColor yellowColor];
        [self addSubview:contentBGView];
        _contentBGView = contentBGView;
        
        _titleLabel = [[UILabel alloc]init ];
        _titleLabel.font = FONT_OF_SIZE(15);
        _titleLabel.numberOfLines = 0;
//        _titleLabel.backgroundColor = [UIColor redColor];
        [contentBGView addSubview:_titleLabel];

        _imageView = [[UIImageView alloc]init];
        _imageView.contentMode =UIViewContentModeScaleAspectFill;
//        _imageView.backgroundColor = [UIColor blueColor];
        _imageView.clipsToBounds  =YES;
        [self addSubview:_imageView];
        
        _typeLabel = [[UILabel alloc]init];
//        _typeLabel.backgroundColor = [UIColor redColor];
        _typeLabel.clipsToBounds = YES;
        _typeLabel.font = FONT_OF_SIZE(12);
        _typeLabel.textColor = RGB(249, 151, 57);
        _typeLabel.textAlignment = NSTextAlignmentCenter;
        [_typeLabel.layer setCornerRadius:10];
        [_typeLabel.layer setBorderWidth:1.0];
        [self addSubview:_typeLabel];
        
        
        _timeLabel = [[UILabel alloc]init];
        _timeLabel.font = FONT_OF_SIZE(13);
//        _timeLabel.backgroundColor = [UIColor redColor];
        _timeLabel.textColor = RGB(151, 151, 151);
        [self addSubview:_timeLabel];
        
        _visitLabel = [[UILabel alloc]init];
//        _visitLabel.backgroundColor = [UIColor redColor];
        _visitLabel.font = FONT_OF_SIZE(13);
        _visitLabel.textAlignment = NSTextAlignmentRight;
        _visitLabel.textColor = RGB(151, 151, 151);
        [self addSubview:_visitLabel];

    }
    
    return self;
    
}

//"ID":"1",
//"contentID":"2",
//"channelID":"26",
//"channelName":"湖南卫视",
//"epgStartTime":"201705121500",
//"epgEndTime":"201705121800",
//"contentStatus":"1",
//"contentName":"《人民》热播带动小说原著大卖 文学分享会举行",
//"contentDes":"testForContentListBySubColumnID",
//"peopleCount":"100",
//"updateTime":"15:00",
//"contentType":"1",
//"sortInx":"1",
//"imageUrlFlg":"1",
//"imageUrlList":[
//                {
//                    "ImageUrl":"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1494577668868&di=dda891fce9fe0732014173c0e3a4b0ca&imgtype=0&src=http%3A%2F%2Fwww.sinaimg.cn%2Fdy%2Fslidenews%2F4_img%2F2012_34%2F703_731460_296623.jpg"
//                }
//                ],
//"targetUrl":"https://www.baidu.com"



//contentType:内容类型，1表示图文类型，2表示点播类型，3表示直播类型，4表示纯图类型，5表示广告类型
-(void)setModel:(ContentModel *)model
{
    _model = model;
    
    switch (model.contentType) {
        case 1:{
            _contentBGView.frame = CGRectMake(5,5, SCREEN_WIDTH*2/3-EDAGEINSET, 60);
            _titleLabel.text = model.contentName;
            CGSize fitSize = [UILabel sizeWithText: _titleLabel.text andFont:FONT_OF_SIZE(15) andMaxSize:CGSizeMake(_contentBGView.width,1000)];
            _titleLabel.frame = CGRectMake(0,0, fitSize.width, fitSize.height);
            
            
            _imageView.hidden = NO;
            _imageView.frame = CGRectMake(MaxX(_contentBGView)+EDAGEINSET, (RECOMMENDCELLHEIGHT -(RECOMMENDCELLHEIGHT - EDAGEINSET*2))*0.5, SCREEN_WIDTH/3.0- EDAGEINSET,RECOMMENDCELLHEIGHT - EDAGEINSET*2);
            NSString *URLString= model.imageUrlList[0][@"ImageUrl"];
            [_imageView sd_setImageWithURL:[NSURL URLWithString:URLString]];
            
            _typeLabel.text = @"图文";
            _typeLabel.frame = CGRectMake(EDAGEINSET, MaxY(_contentBGView)+EDAGEINSET, 36, 20);
            [_typeLabel.layer setBorderColor:RGB(249, 151, 57).CGColor];
            
            
            _timeLabel.text = model.updateTime;
            CGSize fitzie1 =[UILabel sizeWithText:_timeLabel.text andFont:FONT_OF_SIZE(13) andMaxSize:CGSizeMake(1000, 1000)];
            _timeLabel.frame = CGRectMake(MaxX(_typeLabel)+EDAGEINSET, _typeLabel.top+(20-fitzie1.height)*0.5, fitzie1.width, fitzie1.height);
            
            _visitLabel.text = [NSString stringWithFormat:@"%@人看过",model.peopleCount];
            CGSize fitSize2 = [UILabel sizeWithText:_visitLabel.text andFont:FONT_OF_SIZE(13) andMaxSize:CGSizeMake(1000, 1000)];
            
            _visitLabel.frame = CGRectMake(MaxX(_contentBGView) - fitSize2.width, _typeLabel.top+(20-fitzie1.height)*0.5, fitSize2.width, fitSize2.height);
            
         }
            
            break;
        case 2:
        {
            _contentBGView.frame = CGRectMake(5,5, SCREEN_WIDTH*2/3-EDAGEINSET, 60);
            _titleLabel.text = model.contentName;
            CGSize fitSize = [UILabel sizeWithText: _titleLabel.text andFont:FONT_OF_SIZE(15) andMaxSize:CGSizeMake(_contentBGView.width,1000)];
            _titleLabel.frame = CGRectMake(0,0, fitSize.width, fitSize.height);
            
            
            _imageView.hidden = NO;
            _imageView.frame = CGRectMake(MaxX(_contentBGView)+EDAGEINSET, (RECOMMENDCELLHEIGHT -(RECOMMENDCELLHEIGHT - EDAGEINSET*2))*0.5, SCREEN_WIDTH/3.0- EDAGEINSET,RECOMMENDCELLHEIGHT - EDAGEINSET*2);
            NSString *URLString= model.imageUrlList[0][@"ImageUrl"];
            [_imageView sd_setImageWithURL:[NSURL URLWithString:URLString]];
            
            _typeLabel.text = @"点播";
            _typeLabel.frame = CGRectMake(EDAGEINSET, MaxY(_contentBGView)+EDAGEINSET, 36, 20);
            [_typeLabel.layer setBorderColor:RGB(249, 151, 57).CGColor];
            
            
            _timeLabel.text = model.updateTime;
            CGSize fitzie1 =[UILabel sizeWithText:_timeLabel.text andFont:FONT_OF_SIZE(13) andMaxSize:CGSizeMake(1000, 1000)];
            _timeLabel.frame = CGRectMake(MaxX(_typeLabel)+EDAGEINSET, _typeLabel.top+(20-fitzie1.height)*0.5, fitzie1.width, fitzie1.height);
            
            _visitLabel.text = [NSString stringWithFormat:@"%@人看过",model.peopleCount];
            CGSize fitSize2 = [UILabel sizeWithText:_visitLabel.text andFont:FONT_OF_SIZE(13) andMaxSize:CGSizeMake(1000, 1000)];
            
            _visitLabel.frame = CGRectMake(MaxX(_contentBGView) - fitSize2.width, _typeLabel.top+(20-fitzie1.height)*0.5, fitSize2.width, fitSize2.height);
            
        }
            
            break;
        case 3:
        {
            _contentBGView.frame = CGRectMake(5,5, SCREEN_WIDTH*2/3-EDAGEINSET, 60);
            _titleLabel.text = model.contentName;
            CGSize fitSize = [UILabel sizeWithText: _titleLabel.text andFont:FONT_OF_SIZE(15) andMaxSize:CGSizeMake(_contentBGView.width,1000)];
            _titleLabel.frame = CGRectMake(0,0, fitSize.width, fitSize.height);
            
            
            _imageView.hidden = NO;
            _imageView.frame = CGRectMake(MaxX(_contentBGView)+EDAGEINSET, (RECOMMENDCELLHEIGHT -(RECOMMENDCELLHEIGHT - EDAGEINSET*2))*0.5, SCREEN_WIDTH/3.0- EDAGEINSET,RECOMMENDCELLHEIGHT - EDAGEINSET*2);
            NSString *URLString= model.imageUrlList[0][@"ImageUrl"];
            [_imageView sd_setImageWithURL:[NSURL URLWithString:URLString]];
            
            _typeLabel.text = @"直播";
            _typeLabel.frame = CGRectMake(EDAGEINSET, MaxY(_contentBGView)+EDAGEINSET, 36, 20);
            [_typeLabel.layer setBorderColor:RGB(249, 151, 57).CGColor];
            
            
            _timeLabel.text = model.updateTime;
            CGSize fitzie1 =[UILabel sizeWithText:_timeLabel.text andFont:FONT_OF_SIZE(13) andMaxSize:CGSizeMake(1000, 1000)];
            _timeLabel.frame = CGRectMake(MaxX(_typeLabel)+EDAGEINSET, _typeLabel.top+(20-fitzie1.height)*0.5, fitzie1.width, fitzie1.height);
            
            _visitLabel.text = [NSString stringWithFormat:@"%@人看过",model.peopleCount];
            CGSize fitSize2 = [UILabel sizeWithText:_visitLabel.text andFont:FONT_OF_SIZE(13) andMaxSize:CGSizeMake(1000, 1000)];
            
            _visitLabel.frame = CGRectMake(MaxX(_contentBGView) - fitSize2.width, _typeLabel.top+(20-fitzie1.height)*0.5, fitSize2.width, fitSize2.height);
        }
            
            break;
        case 4:
        {
            _contentBGView.frame = CGRectMake(5,5, SCREEN_WIDTH*2/3-EDAGEINSET, 60);
            _titleLabel.text = model.contentName;
            CGSize fitSize = [UILabel sizeWithText: _titleLabel.text andFont:FONT_OF_SIZE(15) andMaxSize:CGSizeMake(_contentBGView.width,1000)];
            _titleLabel.frame = CGRectMake(0,0, fitSize.width, fitSize.height);
            
            
            _imageView.hidden = NO;
            _imageView.frame = CGRectMake(MaxX(_contentBGView)+EDAGEINSET, (RECOMMENDCELLHEIGHT -(RECOMMENDCELLHEIGHT - EDAGEINSET*2))*0.5, SCREEN_WIDTH/3.0- EDAGEINSET,RECOMMENDCELLHEIGHT - EDAGEINSET*2);
            NSString *URLString= model.imageUrlList[0][@"ImageUrl"];
            [_imageView sd_setImageWithURL:[NSURL URLWithString:URLString]];
            
            _typeLabel.text = @"纯图";
            _typeLabel.frame = CGRectMake(EDAGEINSET, MaxY(_contentBGView)+EDAGEINSET, 36, 20);
            [_typeLabel.layer setBorderColor:RGB(249, 151, 57).CGColor];
            
            
            _timeLabel.text = model.updateTime;
            CGSize fitzie1 =[UILabel sizeWithText:_timeLabel.text andFont:FONT_OF_SIZE(13) andMaxSize:CGSizeMake(1000, 1000)];
            _timeLabel.frame = CGRectMake(MaxX(_typeLabel)+EDAGEINSET, _typeLabel.top+(20-fitzie1.height)*0.5, fitzie1.width, fitzie1.height);
            
            _visitLabel.text = [NSString stringWithFormat:@"%@人看过",model.peopleCount];
            CGSize fitSize2 = [UILabel sizeWithText:_visitLabel.text andFont:FONT_OF_SIZE(13) andMaxSize:CGSizeMake(1000, 1000)];
            
            _visitLabel.frame = CGRectMake(MaxX(_contentBGView) - fitSize2.width, _typeLabel.top+(20-fitzie1.height)*0.5, fitSize2.width, fitSize2.height);
        }
            
            break;
        case 5:
        {
            _contentBGView.frame = CGRectMake(5,5, SCREEN_WIDTH*2/3-EDAGEINSET, 60);
            _titleLabel.text = model.contentName;
            CGSize fitSize = [UILabel sizeWithText: _titleLabel.text andFont:FONT_OF_SIZE(15) andMaxSize:CGSizeMake(_contentBGView.width,1000)];
            _titleLabel.frame = CGRectMake(0,0, fitSize.width, fitSize.height);
            
            
            _imageView.hidden = NO;
            _imageView.frame = CGRectMake(MaxX(_contentBGView)+EDAGEINSET, (RECOMMENDCELLHEIGHT -(RECOMMENDCELLHEIGHT - EDAGEINSET*2))*0.5, SCREEN_WIDTH/3.0- EDAGEINSET,RECOMMENDCELLHEIGHT - EDAGEINSET*2);
            NSString *URLString= model.imageUrlList[0][@"ImageUrl"];
            [_imageView sd_setImageWithURL:[NSURL URLWithString:URLString]];
            
            _typeLabel.text = @"广告";
            _typeLabel.frame = CGRectMake(EDAGEINSET, MaxY(_contentBGView)+EDAGEINSET, 36, 20);
            [_typeLabel.layer setBorderColor:RGB(249, 151, 57).CGColor];
            
            
            _timeLabel.text = model.updateTime;
            CGSize fitzie1 =[UILabel sizeWithText:_timeLabel.text andFont:FONT_OF_SIZE(13) andMaxSize:CGSizeMake(1000, 1000)];
            _timeLabel.frame = CGRectMake(MaxX(_typeLabel)+EDAGEINSET, _typeLabel.top+(20-fitzie1.height)*0.5, fitzie1.width, fitzie1.height);
            
            _visitLabel.text = [NSString stringWithFormat:@"%@人看过",model.peopleCount];
            CGSize fitSize2 = [UILabel sizeWithText:_visitLabel.text andFont:FONT_OF_SIZE(13) andMaxSize:CGSizeMake(1000, 1000)];
            
            _visitLabel.frame = CGRectMake(MaxX(_contentBGView) - fitSize2.width, _typeLabel.top+(20-fitzie1.height)*0.5, fitSize2.width, fitSize2.height);
        }
            
            break;
        default:
            break;
    }
    
    
}

+ (instancetype)cellWithTableView:(UITableView *)tableView{
    static NSString *identifier = @"cell";
    RecommendCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil) {
        cell = [[RecommendCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    return cell;
    
}


@end
